<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function list(){
				var xhr=new XMLHttpRequest();
				xhr.open("GET",`/pro/v1/list`,true);
				xhr.onreadystatechange=function(){
					if(xhr.readyState==4&&xhr.status==200){
						var r=xhr.responseText;
						var arr=JSON.parse(r);
							//表头
							htmlStr=`
						   	<table border="1">
						   		<tr>
						   			<th>用户昵称</th>
						   			<th>用户邮箱</th>
						   			<th>电话</th>
						   			<th>真实姓名</th>
						   			<th>性别</th>
						   			<th>操作</th>
						   		</tr>
							`;
							//循环
							for(var i=0;i<arr.length;i++){
								var sex="不详";
								if(arr[i].gender==1){
									sex="男";
								}else if(arr[i].gender==0){
									sex="女";
								}else{
									sex="不详";
								}
								htmlStr+=`
								<tr>
									<td>${arr[i].uname}</td>
									<td>${arr[i].email}</td>
									<td>${arr[i].phone}</td>
									<td>${arr[i].user_name}</td>
									<td>${sex}</td>
									<td>
									<a href="javascript:del(${arr[i].uid})">删除</a>
									<a href="pro_search.html?uid=${arr[i].uid}">修改</a>
									</td>
								</tr>
								`;
						}
						//表尾
						htmlStr+=`</table>`;
						d1.innerHTML=htmlStr;
					}
				}
				xhr.send();
			}
			function del(_uid){
				// var _uid=uid.value;
				var xhr=new XMLHttpRequest();
				xhr.open("delete",`/pro/v1/del/${_uid}`,true);
				xhr.onreadystatechange=function(){
					if(xhr.readyState==4&&xhr.status==200){
						var r=xhr.responseText;
						if(r==1){
							alert("删除成功");
							// location.href="pro_list.html";
							list();
						}else{
							alert("删除失败");
						}
						// d1.innerHTML=r;
					}
				}
				xhr.send();
			}
		</script>
	</head>
	<body onload="list()">
		<div id="d1">
			
		</div>
		<table>
			
		</table>
		
	</body>
</html>
